import request from '@/utils/request'
import { API_ENDPOINTS } from './config'
// 白蚁项目
export const termite = {
  // 获取小区基础信息列表
  getAddressQuery(data) {
    return request({
      url: API_ENDPOINTS.TERMITE.AddressQuery,
      method: 'post',
      data
    })
  },
  // 获取小区基础信息列表
  getSectList(data) {
    return request({
      url: API_ENDPOINTS.TERMITE.GetSectList,
      method: 'post',
      data
    })
  },
  // 获取白蚁防止单位
  getCompany(query) {
    return request({
      url: API_ENDPOINTS.TERMITE.GETCOMPANY,
      method: 'get',
      query
    })
  },
  // 获取白蚁防治单位
  getCompanyList(data) {
    return request({
      url: API_ENDPOINTS.TERMITE.GETCOMPANYLIST,
      method: 'post',
      data
    })
  },
  // 防治企业荣誉
  getCompanyHoner(params) {
    return request({
      url: API_ENDPOINTS.TERMITE.HonorQuery,
      method: 'get',
      params
    })
  },
  // 移动端监测点管理数据查询
  queryMonitorPointMb(data) {
    return request({
      url: API_ENDPOINTS.TERMITE.SEARCH,
      method: 'post',
      data
    })
  },
  // 项目名称查询
  queryMonitorPointMbProjectName() {
    return request({
      url: API_ENDPOINTS.TERMITE.PROJECTNAME,
      method: 'get'
    })
  },
  // 移动端监测现场处理
  handleMonitorPointMb(data) {
    return request({
      url: API_ENDPOINTS.TERMITE.HANDLEPOINT,
      method: 'post',
      data
    })
  },
  // 获取用户信息
  getToken(token) {
    return request({
      url: '/external/encryptGetUserDetail',
      method: 'get',
      headers: {
        'isToken': false
      },
      params: {
        userToken: token
      }
    })
  },
  // 获取用户信息(新)
  getTokenNew(data) {
    return request({
      url: '/external/encryptGetUserDetail/new',
      method: 'post',
      headers: {
        'isToken': false
      },
      data
    })
  },
  // 防治方案执行情况
  getPreventionControlStatus(params) {
    return request({
      url: '/termite-mb/preventionControlStatus',
      method: 'get',
      params
    })
  },
  // 防治企业职称人员情况
  getPreventionControlOperatorQuery(params) {
    return request({
      url: '/termite-mb/preventionControlOperatorQuery',
      method: 'get',
      params
    })
  },
  // 防治企业负面信息查询
  getPreventionControlNegativeQuery(params) {
    return request({
      url: '/termite-mb/preventionControlNegativeQuery',
      method: 'get',
      params
    })
  },
}
// 用户相关API
export const userApi = {
  // 用户登录
  login(data) {
    return request({
      url: API_ENDPOINTS.USER.LOGIN,
      method: 'post',
      data
    })
  },

  // 用户注册
  register(data) {
    return request({
      url: API_ENDPOINTS.USER.REGISTER,
      method: 'post',
      data
    })
  },

  // 获取用户信息
  getUserInfo() {
    return request({
      url: API_ENDPOINTS.USER.INFO,
      method: 'get'
    })
  },

  // 用户登出
  logout() {
    return request({
      url: API_ENDPOINTS.USER.LOGOUT,
      method: 'post'
    })
  }
}

// 上报相关API
export const reportApi = {
  // 获取上报列表
  getReportList(params = {}) {
    return request({
      url: API_ENDPOINTS.REPORT.LIST,
      method: 'get',
      params
    })
  },

  // 创建上报
  createReport(data) {
    return request({
      url: API_ENDPOINTS.REPORT.CREATE,
      method: 'post',
      data
    })
  },

  // 更新上报状态
  updateReport(id, data) {
    return request({
      url: `${API_ENDPOINTS.REPORT.UPDATE}/${id}`,
      method: 'put',
      data
    })
  },

  // 删除上报
  deleteReport(id) {
    return request({
      url: `${API_ENDPOINTS.REPORT.DELETE}/${id}`,
      method: 'delete'
    })
  },

  // 获取上报详情
  getReportDetail(id) {
    return request({
      url: `${API_ENDPOINTS.REPORT.DETAIL}/${id}`,
      method: 'get'
    })
  }
}

// 文件上传API
export const uploadApi = {
  // 上传图片
  uploadImage(file) {
    const formData = new FormData()
    formData.append('multipartFile', file)

    return request({
      url: API_ENDPOINTS.UPLOAD.IMAGE,
      method: 'post',
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },

  // 上传文件
  uploadFile(file) {
    const formData = new FormData()
    formData.append('file', file)

    return request({
      url: API_ENDPOINTS.UPLOAD.FILE,
      method: 'post',
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  }
}

// 通用请求方法
export const api = {
  get(url, params, config = {}) {
    return request({
      url,
      method: 'get',
      params,
      ...config
    })
  },

  post(url, data, config = {}) {
    return request({
      url,
      method: 'post',
      data,
      ...config
    })
  },

  put(url, data, config = {}) {
    return request({
      url,
      method: 'put',
      data,
      ...config
    })
  },

  delete(url, config = {}) {
    return request({
      url,
      method: 'delete',
      ...config
    })
  }
}

// 导出所有API
export default {
  termite,
  user: userApi,
  report: reportApi,
  upload: uploadApi,
  ...api
} 